

DEFINE VARIABLE part LIKE pt_part .

DEFINE VARIABLE um LIKE pt_um .

DEFINE VARIABLE ptdesc AS CHARACTER.

DEFINE STREAM bf.

DEFINE VARIABLE str AS CHARACTER.

INPUT FROM VALUE("f:\hk_src\audit\partdata.csv") .

OUTPUT STREAM bf TO VALUE("f:\hk_src\audit\pt_mstr.txt").

REPEAT ON ERROR UNDO, RETRY :

    IMPORT DELIMITER "," part um ptdesc NO-ERROR .

    PUT STREAM bf "@@batchload ppptmt04.p" SKIP .

    EXPORT STREAM bf part  .

    FIND FIRST pt_mstr NO-LOCK WHERE pt_part = SUBSTRING(part, 1, LENGTH(part) - 1) 
        OR pt_part = SUBSTRING(part, 1, LENGTH(part) - 1) + "R" NO-ERROR.

    EXPORT STREAM bf um pt_desc1 pt_desc2 .

    str = """" + pt_prod_line + """ """ + STRING(pt_add) + """ - - """ + pt_part_type 
        + """ """ + pt_status + """ """ + pt_group + """" .

    PUT STREAM bf UNFORMATTED str SKIP .


    PUT STREAM bf "@@end" SKIP.

END.
